


export class Chapter {
  constructor(public state: LDChapter.Chapter) { }

  ended = false;
  currentFrameId = 0;

  get index() {
    if (this.state.frames.structure.some((str) => str.id == this.currentFrameId)) {
      return this.state.frames.structure.findIndex((str) => str.id == this.currentFrameId);
    }
    return -1;
  }

  get currentFrame() {
    return this.getFrame(this.currentFrameId);
  }

  next(frameId?: number) {
    if (this.currentFrame.nextId) {
      this.currentFrameId = frameId ?? this.currentFrame.nextId;
    } else {
      this.ended = true;
    }
  }

  getFrame(frameId: number) {
    return this.state.frames.map[frameId];
  }

  getResource(resourceId: number) {
    return this.state.resources[resourceId];
  }

  getRole(roleId: number) {
    return this.state.roles[roleId];
  }
}
